package org.jieshen.m1.d9;

public class Solution {
    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int size = releaseTimes.length;
        int maxTime = -1;
        int time = -1;
        char s = ' ';
        for (int i = 0; i < size; i++) {
            if(i==0) {
                maxTime = releaseTimes[0];
                s = keysPressed.charAt(0);
                continue;
            }
            time = releaseTimes[i] - releaseTimes[i-1];
            if(time >= maxTime){
                if(time==maxTime){
                    //持续same ,but char is litter than s,reject
                    if(keysPressed.charAt(i)<s)
                        continue;
                }
                maxTime = time;
                s = keysPressed.charAt(i);
            }
        }
        return s;
    }
    public static void main(String[] args) {
        /**
         * 输入：releaseTimes = [9,29,49,50], keysPressed = "cbcd"
         * 输出："c"
         *releaseTimes = [9,29,49,50], keysPressed = "cbcd"
         * [12,23,36,46,62], keysPressed = "spuda"
         */
        int[] releaseTimes = {1};
        String str = "w";
        char c = new Solution().slowestKey(releaseTimes,str);
        System.out.println(c);
    }
}
